package com.dyh.quickdemozwei.hxfz;

import com.google.common.collect.Lists;
import org.junit.jupiter.api.Test;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.function.Function;

public class TpHxfz {

    /*-NO2硝基-NH2氨基*/


    /*硝基*/
    interface NO2{ }
    /*氨基*/
    interface NH2{ }

    interface AtomicGroup{

    }

//    class X implements Function<String,String>,NO2,NH2{
//
//        @Override
//        public String apply(String s) {
//            return null;
//        }
//    }

    @Test
    public void test(){
        Function fc1 = (Function<String,Integer> &NH2 &NO2) String::length;
        Function fc2 = (Function<String,Integer> &NO2 & NH2) String::length;

//        System.out.println(fc1.getClass().getInterfaces());
//        System.out.println(fc2.getClass().getInterfaces());

        printInterfaces(fc1);
        printInterfaces(fc2);
        System.out.println();
    }

    String checkSjbmUq(List<String> list){
        String msg  = null;
        if (CollectionUtils.isEmpty(list))
            return msg;
        Map<String,Integer> checkMap = new HashMap<>();
        StringBuilder sb = new StringBuilder();
        for (String s : list) {
            Integer i = checkMap.get(s);
            if (i==null){
                checkMap.put(s,1);
            }
            else {
                sb.append(s).append(",");
            }
        }

        if (sb.length()>0)
            msg = String.format("SKU商家编码[%s]在待发布商品内重复，请检查",sb.substring(0,sb.length()-1));

        return msg;

    }

    @Test
    public void test2(){

        List<String> list = Lists.newArrayList("1","2","3","1","2");

        String msg;
        if ( (msg =checkSjbmUq(list))!=null ){
            System.out.println();
        }



        System.out.println();

//        Set<Integer> set = new HashSet<>(list);

//        set.clear();
//        x((Function<String,Integer> &NH2 &NO2) String::length);
    }

    public void x(Function f ){

    }

    public void printInterfaces(Object obj){
        StringBuilder sb = new StringBuilder();
        for (Class<?> anInterface : obj.getClass().getInterfaces()) {
            sb.append(anInterface.getSimpleName()).append(",");
        }
        System.out.println(sb);
    }






}
